package com.hhxy.servlet;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author ghp
 * @date 2022/9/8
 */
//@WebServlet("/servletConfigTestServlet")
public class ServletConfigTestServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request, response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //1、获取ServletConfig对象
        ServletConfig config = this.getServletConfig();
        //2、获取参数encoding对应的值，同时打印测试
        String param = config.getInitParameter("encoding");
        System.out.println(param);//输出：UTF-8

        String name = config.getInitParameter("张三");
        System.out.println(name);//输出：123

        String servletConfigTestServlet = config.getInitParameter("ServletConfigTestServlet");
        System.out.println(servletConfigTestServlet);//输出：null

        String username = config.getInitParameter("username");
        System.out.println(username);//输出：null
    }
}